package com.example.utils;

import lombok.Data;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@Data
public class Invoke {

    private Method method;
    private Object target;

    public static Invoke createInvoke(Method method, Object target) {
        Invoke invoke = new Invoke();
        invoke.setMethod(method);
        invoke.setTarget(target);
        return invoke;
    }

    public Object invoke(Object... args) {
        try {
            return method.invoke(target, args);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    }
}
